package Array;

/**
 * @auther wangchenghao
 * @date 2021/6/5
 **/
public class test8 {
    public static void moveZeroes(int[] nums) {
        int i=0;
        int j=0;
        int temp=0;
        int length=nums.length;
        if(nums.length<2){
            return;
        }else{
            j=1;
        }
        while(i<length&&j<length){
            if(nums[i]==0&&nums[j]==0){
                j++;
            }else if(nums[i]==0&&nums[j]!=0){
                temp=nums[i];
                nums[i]=nums[j];
                nums[j]=temp;
                i++;
                j=i+1;
            }else if(nums[i]!=0&&nums[j]==0){
                i=j;
                j=i+1;
            }else if(nums[i]!=0&&nums[j]!=0){
                i=j+1;
                j=i+1;
            }
        }
    }

    public static void main(String[] args) {
        int nums[]={1,2,0,1,0};
        moveZeroes(nums);
    }
}
